package com.ma.home;

import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ma.R;

/**
 * Created by loma on 2017/10/11.
 */

public class HomeIconText extends LinearLayout {
    public HomeIconText(Context context) {
        super(context);
    }

    public HomeIconText(Context context, AttributeSet attrs) {
        super(context, attrs);
        TypedArray ta = context.obtainStyledAttributes(attrs,  R.styleable.HomeIconText, 0, 0);
        int img=  ta.getResourceId(R.styleable.HomeIconText_icon,0);
        String text=  ta.getString(R.styleable.HomeIconText_text);
         View  view = LayoutInflater.from(context).inflate(R.layout.home_icon_text, this, true);
        TextView textView= (TextView) view.findViewById(R.id.textView);
        ImageView imageView = (ImageView) findViewById(R.id.imageView);
        textView.setText(text);
        imageView.setImageResource(img);


        int width=getScreenHeight(getContext())/4;

        setLayoutParams(new LinearLayout.LayoutParams(width, width));




    }



    /**
            * 获取屏幕高度
          *
           * @param context
            */
          private int getScreenHeight(Context context) {


                 WindowManager wm = (WindowManager) context
                         .getSystemService(Context.WINDOW_SERVICE);

                  return wm.getDefaultDisplay().getWidth();
              }
}
